﻿using Management.Systeam.Domaina;
using Management.Systeam.ErrorCode;
using Management.Systeam.Read.Apis.Application.Command.Useres;
using Management.Systeam.Read.Apis.Auto.UserDto;
using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace Management.Systeam.Read.Apis.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    //[Authorize]
    public class UserValuesController : ControllerBase
    {
        IMediator mediator;

        public UserValuesController(IMediator mediator)
        {
            this.mediator = mediator;
        }
        [HttpPost]
        public async Task<ApiResult<int>> AddUser(AddUserCommand AddUserCommands)
        {
            try
            {
                return await mediator.Send(AddUserCommands);
            }
            catch (Exception)
            {

                throw;
            }
        }
        [AllowAnonymous]
        [HttpGet]
        public async Task<ApiResult<LoginDto>> Login([FromQuery] LoginCommand LoginCommand)
        {
            try
            {
                return await mediator.Send(LoginCommand);
            }
            catch (Exception)
            {
            
                throw;
            }
        }
        [HttpGet]
        public async Task<ApiPeaging<ApiResult<List<UserDtos>>>> ShowUser([FromQuery] ShowUsersCommand ShowUsersCommand)
        {
            try
            {
                return await mediator.Send(ShowUsersCommand);
            }
            catch (Exception)
            {

                throw;
            }
        }
        [HttpDelete]
        public async Task<ApiResult<int>> DelUser([FromQuery] DelUserCommand DelUserCommand)
        {
            try
            {
                return await mediator.Send(DelUserCommand);
            }
            catch (Exception)
            {

                throw;
            }
        }
        [HttpPut]
        public async Task<ApiResult<int>> UpdateUser( UpdateUserCommand UpdateUserCommand)
        {
            try
            {
               
                return await mediator.Send(UpdateUserCommand);
            }
            catch (Exception)
            {

                throw;
            }
        }
        [HttpGet]
        public async Task<ApiResult<int>> UpdatePassWord([FromQuery] UpdatePassWordCommand UpdatePassWordCommand)
        {
            try
            {

                return await mediator.Send(UpdatePassWordCommand);
            }
            catch (Exception)
            {

                throw;
            }
        }
        [HttpGet]
        public async Task<ApiResult<int>> DelUserAll([FromQuery] DelUserAllCommand reques)
        {
            try
            {
                return await mediator.Send(reques);
            }
            catch (Exception)
            {

                throw;
            }
        }
        [HttpGet]
        public async Task<ApiResult<Users>> FistUsers([FromQuery] FistUsersCommand request)
        {
            try
            {
                return await mediator.Send(request);
            }
            catch (Exception)
            {

                throw;
            }
        }
    }
}
